home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / m68k / cc68k.arc / FUNC.C < prev    next >
C/C++ Source or Header  |  1986-10-26  |  4KB  |  131 lines

  1. #include        "stdio.h"
  2. #include        "c.h"
  3. #include        "expr.h"
  4. #include        "gen.h"
  5. #include        "cglbdec.h"
  6.  
  7. /*
  8.  *    68000 C compiler
  9.  *
  10.  *    Copyright 1984, 1985, 1986 Matthew Brandt.
  11.  *  all commercial rights reserved.
  12.  *
  13.  *    This compiler is intended as an instructive tool for personal use. Any
  14.  *    use for profit without the written consent of the author is prohibited.
  15.  *
  16.  *    This compiler may be distributed freely for non-commercial use as long
  17.  *    as this notice stays intact. Please forward any enhancements or question
  18. s
  19.  *    to:
  20.  *
  21.  *        Matthew Brandt
  22.  *        Box 920337
  23.  *        Norcross, Ga 30092
  24.  */
  25. /*      External declarations   */
  26.  
  27. extern SYM          *makeint   ();
  28.  
  29.  
  30.  
  31. /*      function compilation routines           */
  32.  
  33.  funcbody(sp)
  34. /*
  35.  *      funcbody starts with the current symbol being either
  36.  *      the first parameter id or the begin for the local
  37.  *      block. If begin is the current symbol then funcbody
  38.  *      assumes that the function has no parameters.
  39.  */
  40. SYM     *sp;
  41. {       char    *names[20];             /* 20 parameters maximum */
  42.         int     nparms, poffset, i;
  43.         SYM     *sp1;
  44.         global_flag = 0;
  45.         poffset = 8;            /* size of return block */
  46.         nparms = 0;
  47.         if(lastst == id) {              /* declare parameters */
  48.                 while(lastst == id) {
  49.                         names[nparms++] =(char *) litlate(lastid);
  50.                         getsym();
  51.                         if( lastst == comma)
  52.                                 getsym();
  53.                         else
  54.                                 break;
  55.                         }
  56.                 needpunc(closepa);
  57.                 dodecl(sc_member);      /* declare parameters */
  58.                 for(i = 0;i < nparms;++i) {
  59.                         if( (sp1 =(SYM *)search(names[i],lsyms.head)) == 0)
  60.                                 sp1 = makeint(names[i]);
  61.                         if( sp1->tp->size < 4 )
  62.                         {
  63.                             sp1->value.i = poffset +
  64.  (4 - sp1->tp->size);
  65.                             poffset += 4;
  66.                         }
  67.                         else
  68.                         {
  69.                             sp1->value.i =(long)poffset;
  70.                             poffset +=(int)( sp1->tp->size)
  71. ;
  72.                         }
  73.                         sp1->storage_class = sc_auto;
  74.                     }
  75.                 }
  76.         if(lastst != begin)
  77.                 error(ERR_BLOCK);
  78.         else    {
  79.                 cseg();
  80.                 gen_strlab(sp->name);
  81.                 block();
  82.                 funcbottom();
  83.                 }
  84.         global_flag = 1;
  85. }
  86.  
  87. SYM     *makeint(name)
  88. char    *name;
  89. {       SYM     *sp;
  90.         TYP     *tp;
  91.         sp =(SYM *)xalloc(sizeof(SYM));
  92.         tp = (TYP *)xalloc(sizeof(TYP));
  93.         tp->type = bt_long;
  94.         tp->size = 4;
  95.         tp->btp = tp->lst.head = 0;
  96.         tp->sname = 0;
  97.         sp->name = name;
  98.         sp->storage_class = sc_auto;
  99.         sp->tp = tp;
  100.         insert(sp,&lsyms);
  101.         return sp;
  102. }
  103.  
  104.  check_table(head)
  105. SYM     *head;
  106. {       while( head != 0 ) {
  107.                 if( head->storage_class == sc_ulabel )
  108.                         fprintf(list,"*** UNDEFINED LABEL - %s\n",head->name);
  109.                 head = head->next;
  110.                 }
  111. }
  112.  
  113.  funcbottom()
  114. {       nl();
  115.         check_table(lsyms.head);
  116.         lc_auto = 0;
  117.         fprintf(list,"\n\n*** local symbol table ***\n\n");
  118.         list_table(&lsyms,0);
  119.         fprintf(list,"\n\n\n");
  120.         release_local();        /* release local symbols */
  121. }
  122.  
  123.  block()
  124. {       needpunc(begin);
  125.         dodecl(sc_auto);
  126.         cseg();
  127.         genfunc(compound());
  128.         flush_peep();
  129. }
  130.  
  131.